﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using XiDainChangAn.OA.IDAL;

namespace XiDainChangAn.OA.AbstractFactory
{
    /// <summary>
    /// 由简单工厂转变抽象工厂
    /// </summary>
    public class AbstractDalFactory
    {
        //数据库访问驱动层实例所在的程序集
        private static readonly string assemblyName = ConfigurationManager.AppSettings["AssemblyName"];
        public static IUserInfoDal GetUserInfoDal()
        {
            //通过反射的方式来创建程序集，这就不需要创建实例了
            //从而就从“简单工厂”变化到“抽象工厂”

            //通过反射，加载对应程序集来创建数据库访问驱动层实例
            return Assembly.Load(assemblyName).CreateInstance(assemblyName+"UserInfoDal") as IUserInfoDal;
        }
        public static IOrderInfoDal GetOrderInfoDal()
        {
            return Assembly.Load(assemblyName).CreateInstance(assemblyName+"OrderInfoDal") as IOrderInfoDal;
        }
    }
}
